package com.mall.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mall.dubbo.mapper.SmsHomeAdvertiseMapper;
import com.mall.model.domain.SmsHomeAdvertise;
import org.apache.commons.lang.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author xyiaao
 * @description 针对表【sms_home_advertise(首页轮播广告表)】的数据库操作Api实现
 * @createDate 2022-03-29 19:46:09
 */
@DubboService
class SmsHomeAdvertiseApiImpl extends ServiceImpl<SmsHomeAdvertiseMapper, SmsHomeAdvertise>
        implements SmsHomeAdvertiseApi {

    @Autowired
    private SmsHomeAdvertiseMapper smsHomeAdvertiseMapper;

    @Override
    public Page<SmsHomeAdvertise> listPage(Integer pageNum, Integer pageSize, String name, Integer type, String endTime) {

        LambdaQueryWrapper<SmsHomeAdvertise> lqw = new LambdaQueryWrapper<>();
        lqw.like(StringUtils.isNotEmpty(name), SmsHomeAdvertise::getName, name);
        lqw.eq(type != null, SmsHomeAdvertise::getType, type);
        lqw.apply(StringUtils.isNotEmpty(endTime), "DATE_FORMAT(end_time, '%Y-%m-%d') = {0}", endTime);
        Page<SmsHomeAdvertise> page = new Page<>(pageNum, pageSize);

        return smsHomeAdvertiseMapper.selectPage(page, lqw);

    }

    @Override
    public void updateByAdvertise(Integer id, SmsHomeAdvertise advertise) {

        LambdaQueryWrapper<SmsHomeAdvertise> lqw = new LambdaQueryWrapper<>();
        lqw.eq(id != null, SmsHomeAdvertise::getId, id);
        smsHomeAdvertiseMapper.update(advertise, lqw);
    }

}




